import { Label, Vec3 } from "cc";
import { aa } from "../frame/FrameCore";
import { SpineCtrl } from "../ctrl/SpineCtrl";
import { ui } from "../frame/common/Enums";
import { OpponentCtrl } from "../ctrl/OpponentCtrl";

const tempV3 = new Vec3();
class CommonMgr {

    showHand(pos:Vec3,scale:number = 1.5,worldSpace:boolean = false) {
        const emoji = aa.res.get("hand");
        emoji.setScale(scale,scale);
        emoji.parent = aa.global.layers[6];
        if(worldSpace) {
            emoji.worldPosition = pos;
        }else{
            emoji.position = pos;
        }
        return emoji;
    }

 

    showHeart(value:number){
        const heart = aa.res.get("heart", aa.global.layers[6]);
        heart.getChildByName("label").getComponent(Label).string =((value>=0)?"+":"-")+Math.abs(value);
    }


    showEmoji(value: number = 1,offset = 120) {

        value = Math.floor(value);

        let emojiIndex = null;

        switch (value) {
            case 0:
            case 1:
                emojiIndex = 2;
                break;
            case 2:
            case 3:
                emojiIndex = 4;
                break;
            case 4:
            case 5:
                emojiIndex = 12;
                break;
            case 6:
            case 7:
                emojiIndex = 3;
                break;
            case 8:
            case 9:
            case 10:
                emojiIndex = 1;
                break;
            case -1:
            case -2:
                emojiIndex = 5;
                break;
            case -3:
            case -4:
                emojiIndex = 6;
                break;
            case -5:
            case -6:
            case -7:
                emojiIndex = 7;
                break;
            case -8:
            case -9:
            case -10:
                emojiIndex = 9;
                break;
            default:
                break;
        }
        if(!emojiIndex) return;
        Vec3.copy(tempV3, aa.global.playerCtrl.headNub.worldPosition);
        tempV3.y -= 0.1;
        aa.global.cameras[1].convertToUINode(tempV3, aa.global.layers[6], tempV3);
        /* screen space pos to  3d world position under this camera*/
        tempV3.x -= offset;
        const emoji = aa.res.get("Emoji", aa.global.layers[6], tempV3);
        const spineCtrl = emoji.getComponent(SpineCtrl);
        spineCtrl.playAnm("emoji_"+emojiIndex)
    }

}

const commonMgr = new CommonMgr;

export default commonMgr;